package edu.java.homework.hw09.exercises.salads.components;

import edu.java.homework.hw09.exercises.salads.products.Spice;

public class SpiceComponent {

    // --- Instance Variables --------------------------------------------------
    private Spice spice = null;
    private double weight = 0.0d;

    private static final String PRODUCT_ARG_EXCEPTION = "Spice object is null-pointed.";
    private static final String WEIGHT_ARG_EXCEPTION = "The weight of the product could NOT be negative number.";

    // --- Constructors --------------------------------------------------------
    public SpiceComponent(Spice spice) {
	this(spice, 0);
    }

    public SpiceComponent(Spice spice, double weight) {
	// check input parameters
	if (spice == null) {
	    throw new IllegalArgumentException(PRODUCT_ARG_EXCEPTION);
	}
	if (weight < 0) {
	    throw new IllegalArgumentException(WEIGHT_ARG_EXCEPTION);
	}

	this.spice = spice;
	this.weight = weight;
    }

    // --- Getters and Setters -------------------------------------------------
    public Spice getSpice() {
	return spice;
    }

    public void setSpice(Spice spice) {
	// check input parameters
	if (spice == null) {
	    throw new IllegalArgumentException(PRODUCT_ARG_EXCEPTION);
	}
	this.spice = spice;
    }

    public double getWeight() {
	return weight;
    }

    public void setWeight(double weight) {
	if (weight < 0) {
	    throw new IllegalArgumentException(WEIGHT_ARG_EXCEPTION);
	}
	this.weight = weight;
    }

    @Override
    public String toString() {
	return getSpice().toString() + ", price: " + getSpice().getPrice()
		+ ", weight: " + getWeight();
    }

}
